home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / ADAWKBK / SOL1-3.ADA < prev    next >
Text File  |  1992-08-25  |  1KB  |  54 lines

  1. -- Problem 1.3
  2. -- by Rick Conn
  3. package example is
  4.  
  5.   function square (item : in float) return float;  -- spec
  6.  
  7.   procedure display (item : in integer);  -- spec
  8.  
  9.   procedure display (item : in float);  -- spec
  10.     -- overloading of the procedure display with different
  11.     -- parameter types is fine in Ada
  12.  
  13. end example;
  14.  
  15. with text_io;
  16. package body example is
  17.  
  18.   package int_io is new text_io.integer_io (integer);
  19.   package flt_io is new text_io.float_io (float);
  20.  
  21.   function square (item : in float) return float is -- body
  22.   begin
  23.     return item * item;
  24.   end square;
  25.  
  26.   procedure display (item : in integer) is  -- body
  27.   begin
  28.     text_io.put ("Integer number: ");
  29.     int_io.put (item, 4);
  30.     text_io.new_line;
  31.   end display;
  32.  
  33.   procedure display (item : in float) is  -- body
  34.   begin
  35.     text_io.put ("Floating point number: ");
  36.     flt_io.put (item, 5, 4, 0);
  37.     text_io.new_line;
  38.   end display;
  39.  
  40. end example;
  41.  
  42. with example;
  43. procedure demo is
  44.  
  45.   result : float;
  46.  
  47. begin
  48.  
  49.   result := example.square (2.2);
  50.   example.display (result);  -- float display
  51.   example.display (2);       -- integer display
  52.  
  53. end demo;
  54.